package com.hqyj.module.StaffManage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.module.StaffManage.dao.StaffManageDao;
import com.hqyj.module.StaffManage.entity.Dept;
import com.hqyj.module.StaffManage.entity.MyPage;
import com.hqyj.module.StaffManage.entity.Staff;
import com.hqyj.module.StaffManage.service.StaffManageService;
import com.hqyj.module.clock.pojo.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description：StaffManageServiceImpl
 * @Author ：Cwd
 * @Date ：2021/10/8 16:59
 */
@Service
public class StaffManageServiceImpl implements StaffManageService {

    @Autowired
    private StaffManageDao staffManageDao;

    @Override
    public HashMap<String, Object> add(Staff staff) {
        HashMap<String,Object> map = new HashMap<>();
        int num = staffManageDao.insertStaff(staff);
        if (num > 0){
            map.put("info","新增成功");
        }else {
            map.put("info","新增失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> update(Staff staff) {
        HashMap<String,Object> map = new HashMap<>();
        int num = staffManageDao.updateStaff(staff);
        if (num > 0){
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }

    @Override
    public PageInfo<Staff> list(SearchBean searchBean) {
        searchBean.initSearchBean();
        PageHelper.startPage(searchBean.getCurrentPage(), searchBean.getPageSize());
        return new PageInfo<>(Optional
                .ofNullable(staffManageDao.list(searchBean))
                .orElse(Collections.emptyList()));
    }

    @Override
    public HashMap<String, Object> insertDept(Dept dept) {
        HashMap<String,Object> map = new HashMap<>();
        int num = staffManageDao.insertDate(dept);
        if (num > 0){
            map.put("info","新增成功");
        }else {
            map.put("info","新增失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> updateDept(Dept dept) {
        HashMap<String,Object> map = new HashMap<>();
        int num = staffManageDao.updateDept(dept);
        if (num > 0){
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }

    @Override
    public PageInfo<Dept> listDept(SearchBean searchBean) {
        searchBean.initSearchBean();
        PageHelper.startPage(searchBean.getCurrentPage(), searchBean.getPageSize());
        return new PageInfo<>(Optional
                .ofNullable(staffManageDao.listDept(searchBean))
                .orElse(Collections.emptyList()));
    }
}
